package com.hms.entity;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 部门结构. <br>
 * 类详细说明.
 * <p>
 * Copyright: Copyright (c) 2013-4-13 上午11:28:05
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * 
 * @author wangpz@c-platform.com
 * @version 1.0.0
 */
@Entity
@Table(name = "td_department", uniqueConstraints = { @UniqueConstraint(columnNames = {
		"name", "parentId" }) })
public class TdDepartment extends BaseEntity {

	/** serialVersionUID */
	private static final long serialVersionUID = 1L;

	public static final String PATH_SPLIT = ",";

	// 名字
	private String name;

	// 节点路径
	private String path;

	// 联系人名
	private String contactName;

	// 联系电话
	private String telephone;

	// email
	private String email;

	// 上级部门
	private TdDepartment parent;

	// 下级部门
	private Set<TdDepartment> childrenDepartment;

	@Column(name = "name", nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "path", nullable = false)
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	@Column(name = "contactname", nullable = false)
	public String getContactName() {
		return contactName;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	@Column(name = "telephone")
	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Column(name = "email")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parentId")
	public TdDepartment getParent() {
		return parent;
	}

	public void setParent(TdDepartment parent) {
		this.parent = parent;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
	@Cascade(value = { CascadeType.DELETE })
	@OrderBy(" name asc")
	public Set<TdDepartment> getChildrenDepartment() {
		return childrenDepartment;
	}

	public void setChildrenDepartment(Set<TdDepartment> childrenDepartment) {
		this.childrenDepartment = childrenDepartment;
	}

}
